import pymysql
from random import Random

def random_str(randomlength=20):
    str = ''
    chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
    length = len( chars ) - 1
    random = Random()
    for i in range( randomlength ):
        if i % 4 == 0 and i != 0:
            str += "-"
        else:
            str += chars[random.randint( 0, length )]

    return str

if __name__ == '__main__':
    db = pymysql.connect( "192.168.0.242", "root", "Kc@123456", "helmet_operate_sit" )
    cursor = db.cursor()
    oredersql = "SELECT oi.order_id,ao.id FROM kc_order_info oi LEFT JOIN kc_agent_info ao on oi.contract_name = ao.agent_name"
    cursor.execute( oredersql )
    fetchall = cursor.fetchall()
    for f in fetchall:
        orderid = f[0]
        id = f[1]
        if id != None and id != '':
            insersql = 'insert into kc_agent_order (id, order_id, agent_id, delete_flag, creat_time) values (uuid(), \''+orderid +'\', \''+id+'\', \'0\', now())'
            cursor.execute(insersql)
            db.commit()


